<?php

class taobaoapi_class{

private $path='taobaoapi'; //当前模块目录
private $dbver=100; //当前模块的数据库版本

public function __construct(){
	global $king;

	$dbver=(int)$king->getModuleVer($this->path);
	if($this->dbver > $dbver){
		if($this->install_update($dbver)){//成功则返回True，则更新数据库中的版本信息
			$array=array(
				'ndbver'=>$this->dbver,
			);
			$king->db->update('%s_module',$array,"kpath='{$this->path}'");
		}
	}
}

/* ------>>> 安装部分 <<<---------------------------- */

public function install(){
	global $king;

	$this->install_update(100);

	$sql='nameid int(11) not null,
	kcontent text null,	
	nshow tinyint(1) not null default 0,
	norder int not null default 0,
	INDEX(nameid)';

	$king->db->createTable('%s_pinglun',$sql,'kid');



	$sql2='ktitle char(100) not null,
	nshow int(10) not null default 0,
	INDEX(ktitle)';
	
	$king->db->createTable('%s_title_pingluen',$sql2,'kid');
	if(!$king->db->getRows_one('SELECT * FROM %s_block where kname=\'内容采集关键词过滤\';')){
				$_array=array(
					'kname'=>'内容采集关键词过滤',
					'kcontent'=>'',
				);
				$king->db->insert('%s_block',$_array);

	}

	//写模块安装记录
	if(!$king->db->getRows_one('SELECT * FROM %s_module where kpath=\''.$this->path.'\';')){
		$_array=array(
			'kname' =>$king->lang->get($this->path.'/name'),
			'kpath' =>$this->path,
			'kdb'   =>'',
			'ndate' =>time(),
			'ndbver'=>$this->dbver,
			'norder'=>$king->db->neworder('%s_module'),
			'nshow'=>0,
			);
		$kid1=$king->db->insert("%s_module",$_array);

		return true;
	}else{
		return false;
	}
}

public function install_update($ver){


	return True;
}



public function k_tag($arrr){
		global $king;
		$as=$king->db->getRows_one("select name from relationships WHERE pid=".$arrr);
		if(empty($as)){
		$king->db->query("delete from %s_pinglun where nameid =".$arrr);
		}
		$kuisz=$king->db->getRows("select name,slug from relationships,metas WHERE relationships.mid=metas.mid and metas.nshow=1 and metas.type = 'tag' and relationships.pid=".$arrr);
		return $kuisz;



}




}

?>
